package shop.view;

import java.util.List;
import shop.controller.HibernateManager;
import shop.model.Product;
import com.opensymphony.xwork2.ActionSupport;
 
 
public class ProductAction extends ActionSupport {
 
    private static final long serialVersionUID = 9149826260758390091L;
    private Product product;
    private List<Product> productList;
    private Long id;
    private HibernateManager hibernateManager;
 
    public ProductAction() {
        hibernateManager = new HibernateManager();
    }
 
    
   
    public String execute() {
        this.productList = hibernateManager.getList();
        System.out.println("execute called");
        return SUCCESS;
    }
 
    public String add() {
    	if(!hibernateManager.checkRepeated("description", product.getDescription())){  
            hibernateManager.add(product);  
        }  
        System.out.println(getProduct());
        this.productList = hibernateManager.getList();
        return SUCCESS;
    }
 
    public String delete() {
        hibernateManager.delete(getId());
        return SUCCESS;
    }
 
    public String update(){  
        hibernateManager.update(product);  
        return "update";  
    }  
    
    
    public Product getProduct() {
        return product;
    }
 
    public List<Product> getProductList() {
        return productList;
    }
 
    public void setProduct(Product product) {
        this.product = product;
    }
 
    public void setProductList(List<Product> productsList) {
        this.productList = productsList;
    }
 
    public Long getId() {
        return id;
    }
 
    public void setId(Long id) {
        this.id = id;
    }
}
